/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pl.tom.social.analyzer.cluster;

import edu.uci.ics.jung.algorithms.blockmodel.EquivalenceRelation;
import edu.uci.ics.jung.algorithms.blockmodel.StructurallyEquivalent;
import edu.uci.ics.jung.algorithms.cluster.ClusterSet;
import edu.uci.ics.jung.algorithms.cluster.EdgeBetweennessClusterer;
import edu.uci.ics.jung.algorithms.cluster.WeakComponentClusterer;
import edu.uci.ics.jung.graph.Graph;
import java.util.HashMap;
import java.util.Map;
import pl.tom.social.analyzer.common.Results;
import pl.tom.social.analyzer.visualizer.AnalysisVisualizer;
import pl.tom.social.common.types.AnalysisType;

/**
 *
 * @author Tom
 */
public class JungCluster {

	public static void EdgeBetweenness(Graph graph, int numEdgesToRemove) {
		EdgeBetweennessClusterer clusterer = new EdgeBetweennessClusterer(numEdgesToRemove);
		ClusterSet clusters = clusterer.extract(graph);
		Results.show(AnalysisVisualizer.clusterSetToJTable(clusters), AnalysisType.Clustering);
	}

	public static void StructurallyEquivalent(Graph graph) {
		EquivalenceRelation se = StructurallyEquivalent.getInstance().getEquivalences(graph);
		Results.show(AnalysisVisualizer.equivalenceRelationToJTable(se), AnalysisType.Clustering);
	}

	public static void WeakComponent(Graph graph) {
		WeakComponentClusterer clusterer = new WeakComponentClusterer();
		ClusterSet clusters = clusterer.extract(graph);
		Results.show(AnalysisVisualizer.clusterSetToJTable(clusters), AnalysisType.Clustering);
	}

//	public static void KMeans(Graph graph, int max_iterations, int convergence_threshold) {
//		KMeansClusterer clusterer = new KMeansClusterer(max_iterations, convergence_threshold);
//		ClusterSet clusters = clusterer.
//		showResult(clusters);
//	}

	public static void EdgeBetweenness(Graph graph, int from, int to, int step) {
		Map<Double, Integer> result = new HashMap<Double, Integer>();
		for(int i = from; i < to + step;i+=step) {
			EdgeBetweennessClusterer clusterer = new EdgeBetweennessClusterer(i);
			ClusterSet clusters = clusterer.extract(graph);
			result.put((double)i, clusters.size());
		}
		Results.show(AnalysisVisualizer.sumToJTable(result), AnalysisType.Clustering);
	}
}
